<!DOCTYPE html>
<html>
<head>
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8"/>
    <title>客户编辑</title>
[#include "../../include/main.ftl"]
[#include "/include/popdialog.ftl"]
    <script>
        var rp = function refreshPage(data) {
            if (data != null) {
                $('#custSn').val(data.sn);
                $('#name').html(data.name);
                $('#custType').val(data.custType);
                $('#custTypeName').html(data.custTypeName);
                $('#IDCard').html(data.IDCard);
                $('#IDAddress').html(data.IDAddress);
                $('#compAddress').html(data.compAddress);
                $('#custLink').attr("href", "/Ins/customer/edit/" + data.sn);
				initCustomerCars(data.sn);
				initDriver();
            }
        };
		
		function initCustomerCars(sn) {
		    $.get('/Ins/Customer/getCars/' + sn, null,
            function(data){
                var tbodyCar = "";
                $.each(data, function(i, val){
                    tbodyCar += "<tr>"+
                                "<td><input type=\"radio\" name=\"custCarSn\" id=\"custCarSn_" + val.sn +"\" value=\"" + val.sn +"\">"+
                                    val.carNo + "</td>"+
                                "<td>"+ val.carKind +"</td>"+
                                "<td>"+ val.brand +"</td>"+
                                "<td>"+val.regDate+"</td>"+
                            "</tr>" ;
                });
                $('#cars').html(tbodyCar);
            },"json")
		}
        function initDriver() {
            if ($('#driverLimit').attr('checked') && $('#custSn').val() != '') {
                $.get('/Ins/Customer/getDrivers/' + $('#custSn').val(), null,
                function(data){
                    var tbodyDriver = "";
                    $.each(data, function(i, val){
                        tbodyDriver += "<tr>"+
                                    "<td><input type=\"checkbox\" name=\"custDriverSn\" id=\"custDriverSn_" + val.sn +"\" value=\""+ val.sn +"\">"+
                                        val.cardNo + "</td>"+
                                    "<td>"+ val.name +"</td>"+
                                    "<td>"+ +val.birthDay +"</td>"+
                                    "<td>"+ val.firstCardDate +"</td>"+
                                "</tr>" ;
                    });
                    $('#drivers').html(tbodyDriver);
                },"json");
                $('#div_drivers').show();
            } else {
                $('#div_drivers').hide();
            }
        }
		
        function selectUser() {
            popDialog("selectUser", "选择客户",
                    "/Ins/customer/select",
                    rp, 600, 600);
        }

        function calcTotalFee() {
            var tf = 0;
            $.each($('input[name*="premium_"]'), function (i, val) {
                var feeid = val.id.substr(val.id.indexOf('_')+1);
                if ($('#fee_'+feeid).attr('checked')) {
                    if (val.value !=null && val.value!="" && !isNaN(val.value)) {
                        tf += parseFloat(val.value);
                    }
                }
            });
            $('#totalFee').html(tf);
        }
		
		function addInsModify(){
			imCount++;
			$("<tr id=\"tr_insModify_"+ imCount + "\"><td colspan=\"2\"><textarea name=\"insModify_" + imCount + 
			"\" id=\"insModify_" + imCount + "\" cols=\"60\" rows=\"5\"></textarea></td>"+
                              "<td>【保存后可上传原件】【<a href=\"javaScript:if (confirm('确定删除？')) delInsModify('insModify_"+
							  imCount + "');\">删除</a>】</td></tr>").appendTo('#InsModify');		
		}
		function delInsModify(sn){
			$('#tr_'+sn).remove();	
		}
		$(function() {
            $("#insList").tabs();
        });
    </script>
</head>
<body>
<div class="ui-widget page">
[#include '../../top.ftl']

    <div class="content">
    [#include '../../leftNav.ftl']
        <div style="width:845px;float: left;padding-left: 5px">
            <div class="ui-widget-content ui-corner-all" style="min-height: 600px;">
                <form name="mainForm" method="post" action="/Ins/policy/save">
                <INPUT TYPE="hidden" NAME="sn" VALUE="${obj.PolicyObj.sn?default('')}">
                 <INPUT TYPE="hidden" NAME="createUser" VALUE="${obj.PolicyObj.createUser?default('')}">
                  <INPUT TYPE="hidden" NAME="createTime" VALUE="${(obj.PolicyObj.createTime?string('yyyy-MM-dd'))?default('')}">
                <INPUT TYPE="hidden" NAME="custSn" id="custSn" VALUE="${obj.PolicyObj.custSn?default('')}">
                    【<a href="/Ins/policy/list">返回保单查询</a>】

                    <div id="contract_base">
                      <p>【被保险人资料】【<a href="javaScript:selectUser();">选择客户</a>】 </p>
                      <table width="100%" border="0" cellspacing="4">
                        <tr>
                          <td bgcolor="#CCCCCC"><p>客户名称 </p></td>
                          <td><span id="name">
                            ${(obj.CustomerObj.name)!''}
                          </span></td>
                          <td bgcolor="#CCCCCC">身份证号 </td>
                          <td><span id="IDCard">
                            ${(obj.CustomerObj.IDCard)!''}
                          </span></td>
                        </tr>
                        <tr>
                          <td bgcolor="#CCCCCC"><p>身份证地址 </p></td>
                          <td colspan="3"><span id="IDAddress">
                            ${(obj.CustomerObj.IDAddress)!''}
                          </span></td>
                        </tr>
                        <tr>
                          <td bgcolor="#CCCCCC"><p>单位地址</p></td>
                          <td colspan="3"><span id="compAddress">
                            ${(obj.CustomerObj.compAddress)!''}
                          </span></td>
                        </tr>
                      </table>
                      <table width="100%" border="0" cellpadding="0" cellspacing="4">
                        <tr>
                          <td colspan="8" bgcolor="#CCCCCC">投保车辆</td>
                        </tr>
                        <tr>
                          <td>车牌号</td>
                          <td>车型型号</td>
                          <td>发动机号</td>
                          <td>识别号</td>
                          <td>初登日期</td>
                          <td>座位数</td>
                          <td>发证日期</td>
                          <td>整备质量</td>
                        </tr>
                        <tbody id="cars">
                          [#list obj.CustomerCars?default([]
                        ) as car]
                        <tr>
                          <td><input type="radio" name="custCarSn" id="custCarSn_${car.sn}" value="${car.sn}">
                            ${car.carNo!""}</td>
                          <td>${car.brand!""}
                            ${car.brandKind!""}</td>
                          <td>${car.eno!""}</td>
                          <td>${car.vin!""}</td>
                          <td>${(car.regDate?string('yyyy-MM-dd'))?default('')}</td>
                          <td>${car.maxPerson?default('')}</td>
                          <td>${(car.cardDate?string('yyyy-MM-dd'))?default('')}</td>
                          <td>${(car.mWeight?string('yyyy-MM-dd'))?default('')}</td>
                        </tr>
                        [/#list]
    </tbody>
  
  <script>$("#custCarSn_${(obj.PolicyObj.custCarSn)!''}").attr("checked",'true');</script>
                      </table>
                      <p>
                          <label>
                                <input type="checkbox" name="provinceLimit"  id="provinceLimit" value="1">
[#if obj.PolicyObj.provinceLimit?default(0) == 1 ]<script>$("#provinceLimit").attr('checked', 'true');</script>[/#if]
                                限省内</label>
                            <label>
                                <input type="checkbox" name="driverLimit" value="1" id="driverLimit" onclick="initDriver();">
[#if obj.PolicyObj.driverLimit?default(0) == 1 ]<script>$("#driverLimit").attr('checked', 'true');</script>[/#if]
                                限驾驶员<br>
                            </label>
                        </p>
                        <div id = "div_drivers">
                          <table width="100%" border="0" cellpadding="0" cellspacing="4">
                            <tr>
                              <td colspan="5" bgcolor="#CCCCCC">驾驶员信息</td>
                            </tr>
                            <tr>
                              <td>姓名</td>
                              <td>性别</td>
                              <td>驾驶证号</td>
                              <td>准驾车型</td>
                              <td>初次领证</td>
                            </tr>
                            <tbody id="drivers">
                              [#list obj.CustomerDrivers?default([]
                            ) as driver]
                            <tr>
                              <td><input type="checkbox" name="custDriverSn" id="custDriverSn_${driver.sn}" value="${driver.sn}">
                                ${driver.name}</td>
                              <td>${driver.sex}</td>
                              <td>${driver.cardNo}</td>
                              <td>${(driver.quasiDriving)?default('')}</td>
                              <td>${(driver.firstCardDate?string('yyyy-MM-dd'))?default('')}</td>
                            </tr>
                            [/#list]
                            <tr>
                              <td colspan="2"></tbody>
                          </table>
</div>
                            <script>
                        [#if obj.PolicyObj.driverLimit?default(0) == 0 ]
						
							$('#div_drivers').hide();
						[#else]
                        	[#list obj.PolicyDrivers?default([]) as d]
							$('#custDriverSn_${d.custDriverSn}').attr('checked', 'true');
							[/#list]
                        
                        [/#if]
							</script>
<div id="insList" style="width:100%">

                                <ul style="border-bottom:#aed0ea 1px solid;">
                                    <li><a href="#biz">商业</a></li>
									<li><a href="#jq">交强车船</a></li>
                                </ul>
                               	<div id="biz">
                      <p>保单号
                        <input type="text"  size="20" id="policyNo" name="policyNo"  >
                        <script>$("#policyNo").val("${(obj.PolicyObj.policyNo)?default('')}");</script>
&nbsp; 【历史保单
<label for="select"></label>
<select name="select" id="select">
  <option value="2011">2011</option>
  <option value="2010">2010</option>
  <option value="2009">2009</option>
  <option value="2008">2008</option>
</select>
<a href="#">查看</a>】</p>
                      <p>保险有效起止日期
                        <input type="text"  size="20" id="insBeginDate" name="insBeginDate" class="validate-date-yyyy-MM-dd" onClick="popCalendar(this)" >
                        
  <script>$("#insBeginDate").val("${(obj.PolicyObj.insBeginDate?string('yyyy-MM-dd'))?default('')}");</script>
  <select name="insBeginDateTime" id="insBeginDateTime">
    <option value="0">零时</option>
    <option value="1">一时</option>
    <option value="2">二时</option>
    <option value="3">三时</option>
    <option value="4">四时</option>
    <option value="5">五时</option>
    <option value="6">六时</option>
    <option value="7">七时</option>
    <option value="8">八时</option>
    <option value="9">九时</option>
    <option value="10">十时</option>
    <option value="11">十一时</option>
    <option value="12">十二时</option>
    <option value="13">十三时</option>
    <option value="14">十四时</option>
    <option value="15">十五时</option>
    <option value="16">十六时</option>
    <option value="17">十七时</option>
    <option value="18">十八时</option>
    <option value="19">十九时</option>
    <option value="20">二十时</option>
    <option value="21">二十一时</option>
    <option value="22">二十二时</option>
    <option value="23">二十三时</option>
    <option value="24" selected>二十四时</option>
  </select>
  <script>$("#insBeginDateTime").val("${(obj.PolicyObj.insBeginDateTime)?default('24')}");</script>
  至
                        <input type="text"  size="20" id="insEndDate" name="insEndDate" class="validate-date-yyyy-MM-dd" onClick="popCalendar(this)" >
                        
  <script>$("#insEndDate").val("${(obj.PolicyObj.insEndDate?string('yyyy-MM-dd'))?default('')}");</script>
  <select name="insEndDateTime" id="insEndDateTime">
    <option value="0">零时</option>
    <option value="1">一时</option>
    <option value="2">二时</option>
    <option value="3">三时</option>
    <option value="4">四时</option>
    <option value="5">五时</option>
    <option value="6">六时</option>
    <option value="7">七时</option>
    <option value="8">八时</option>
    <option value="9">九时</option>
    <option value="10">十时</option>
    <option value="11">十一时</option>
    <option value="12">十二时</option>
    <option value="13">十三时</option>
    <option value="14">十四时</option>
    <option value="15">十五时</option>
    <option value="16">十六时</option>
    <option value="17">十七时</option>
    <option value="18">十八时</option>
    <option value="19">十九时</option>
    <option value="20">二十时</option>
    <option value="21">二十一时</option>
    <option value="22">二十二时</option>
    <option value="23">二十三时</option>
    <option value="24" selected>二十四时</option>
  </select><script>$("#insEndDateTime").val("${(obj.PolicyObj.insEndDateTime)?default('0')}");</script>
                      </p>

                        <p>保险公司
                            <select name="insCompany" id="insCompany">
                            [#list obj.insCompList?default([]) as ic]
                            <option value="${ic.sn}">${ic.name}</option>
                            [/#list]
                            </select><script>$("#insCompany").val("${(obj.PolicyObj.insCompany)?default('')}");</script><script>$("#quoteDate").val("${(obj.PolicyObj.quoteDate?string('yyyy-MM-dd'))?default('')}");</script>
                        <span id="spPolicy"></span> 
                                    <script>
                                    [#list obj.PolicyFileList?default([]) as cid]
									$('#spPolicy').html($('#spPolicy').html()+getFileLink('${cid.sn}'));
                                [/#list]
								</script>
                    【<a href="javaScript:uploadFile('spPolicy','保单','${obj.PolicyObj.sn?default('')}','原件');">上传保单原件</a>】</p>
                        <table width="100%" border="0" cellspacing="1" cellpadding="0">
                            <tr>
                                <td bgcolor="#CCCCCC">险种</td>
                              <td bgcolor="#CCCCCC">保额（元）</td>
                                <td bgcolor="#CCCCCC">保费（元）</td>
                            </tr>
                            [#list obj.feeList?default([]) as fee]
                            <tr>
                                <td><input type="checkbox" name="fee" value="${fee.sn}" id="fee_${fee.sn}" onChange="calcTotalFee();">
                                    ${fee.name}
                                </td>
                                <td>
                              <input type="text"  size="20" id="insured_${fee.sn}" name="insured_${fee.sn}"  ></td>
                                <td><input type="text"  size="20" id="premium_${fee.sn}" name="premium_${fee.sn}" onChange="calcTotalFee();"></td>
                            </tr>
                            [/#list]
                            
                            <tr>
                                <td>小计</td>
                                <td>&nbsp;</td>
                                <td><span id="totalFee"></span></td>
                            </tr>
                            <tr>
                              <td colspan="3" bgcolor="#CECFCE">特别约定</td>
                            </tr>
                            <tr>
                              <td colspan="3"><textarea name="special" id="special" cols="100" rows="5">${(obj.PolicyObj.special)?default('')}</textarea></td>
                            </tr>
                            <tr>
                              <td colspan="3" bgcolor="#CECFCE">批单 【<a href="javaScript:addInsModify();">添加批单</a>】</td>
                            </tr>
                            <tbody id="InsModify">
                            [#if obj.PolicyInsModifys?? && obj.PolicyInsModifys?size > 0]
                            [#list obj.PolicyInsModifys?default([]) as im]
                            <tr id="tr_insModify_${im.sn}">
                              <td colspan="2"><textarea name="insModify_${im.sn}" id="insModify_${im.sn}" cols="60" rows="5">${im.content!''}</textarea></td>
                              <td><span id="spInsModify_${im.sn}"></span> 
                                    <script>
                                    [#list im.ufList?default([]) as cid]
									$('#spInsModify_${im.sn}').html($('#spInsModify_${im.sn}').html()+getFileLink('${cid.sn}'));
                                [/#list]
								</script>
                              【<a href="javaScript:uploadFile('spInsModify_${im.sn}','保单','${im.sn?default('')}','批单');">批单原件</a>】【<a href="javaScript:if (confirm('确定删除?')) delInsModify('insModify_${im.sn}');">删除</a>】</td>
                            </tr>
                            [/#list]
                            <script>var imCount = ${obj.PolicyInsModifys?size};</script>
                            [#else]
                            <script>var imCount = 0;</script>
                            [/#if]
                            </tbody>
                        </table>
                        <script>
                        [#list obj.PolicyInsDetails?default([]) as i]
                        $('#fee_${i.insKind}').attr('checked', 'true');
						$('#insured_${i.insKind}').val('${i.insured}');
						$('#premium_${i.insKind}').val('${i.premium}');
                        [/#list]
						calcTotalFee();
						</script>
                        </div>
                        <div id="jq">
                          <p>保单号
                            <input type="text"  size="20" id="jqPolicyNo" name="jqPolicyNo"  >
                            <script>$("#jqPolicyNo").val("${(obj.PolicyObj.jqPolicyNo)?default('')}");</script>
  &nbsp; 【历史保单
  <label for="select"></label>
  <select name="select2" id="select">
    <option value="2011">2011</option>
    <option value="2010">2010</option>
    <option value="2009">2009</option>
    <option value="2008">2008</option>
  </select>
  <a href="#">查看</a>】</p>
                          <p>保险有效起止日期
                            <input type="text"  size="20" id="jqInsBeginDate" name="jqInsBeginDate" class="validate-date-yyyy-MM-dd" onClick="popCalendar(this)" >
                            <script>$("#jqInsBeginDate").val("${(obj.PolicyObj.jqInsBeginDate?string('yyyy-MM-dd'))?default('')}");</script>
                            <select name="jqInsBeginDateTime" id="jqInsBeginDateTime">
                              <option value="0">零时</option>
                              <option value="1">一时</option>
                              <option value="2">二时</option>
                              <option value="3">三时</option>
                              <option value="4">四时</option>
                              <option value="5">五时</option>
                              <option value="6">六时</option>
                              <option value="7">七时</option>
                              <option value="8">八时</option>
                              <option value="9">九时</option>
                              <option value="10">十时</option>
                              <option value="11">十一时</option>
                              <option value="12">十二时</option>
                              <option value="13">十三时</option>
                              <option value="14">十四时</option>
                              <option value="15">十五时</option>
                              <option value="16">十六时</option>
                              <option value="17">十七时</option>
                              <option value="18">十八时</option>
                              <option value="19">十九时</option>
                              <option value="20">二十时</option>
                              <option value="21">二十一时</option>
                              <option value="22">二十二时</option>
                              <option value="23">二十三时</option>
                              <option value="24" selected>二十四时</option>
                            </select><script>$("#jqInsBeginDateTime").val("${(obj.PolicyObj.jqInsBeginDateTime)?default('24')}");</script>
                            至
  <input type="text"  size="20" id="jqInsEndDate" name="jqInsEndDate" class="validate-date-yyyy-MM-dd" onClick="popCalendar(this)" >
  <script>$("#jqInsEndDate").val("${(obj.PolicyObj.jqInsEndDate?string('yyyy-MM-dd'))?default('')}");</script>
  <select name="jqInsEndDateTime" id="jqInsEndDateTime">
    <option value="0">零时</option>
    <option value="1">一时</option>
    <option value="2">二时</option>
    <option value="3">三时</option>
    <option value="4">四时</option>
    <option value="5">五时</option>
    <option value="6">六时</option>
    <option value="7">七时</option>
    <option value="8">八时</option>
    <option value="9">九时</option>
    <option value="10">十时</option>
    <option value="11">十一时</option>
    <option value="12">十二时</option>
    <option value="13">十三时</option>
    <option value="14">十四时</option>
    <option value="15">十五时</option>
    <option value="16">十六时</option>
    <option value="17">十七时</option>
    <option value="18">十八时</option>
    <option value="19">十九时</option>
    <option value="20">二十时</option>
    <option value="21">二十一时</option>
    <option value="22">二十二时</option>
    <option value="23">二十三时</option>
    <option value="24" selected>二十四时</option>
  </select><script>$("#jqInsEndDateTime").val("${(obj.PolicyObj.jqInsEndDateTime)?default('0')}");</script>
                          </p>
                          <table width="100%" border="0" cellspacing="1" cellpadding="0">
                          <tr>
                            <td bgcolor="#CCCCCC">项目</td>
                            <td bgcolor="#CCCCCC">金额</td>
                          </tr>



                          <tr>
                            <td>交强险</td>
                            <td><label for="jq"></label>
                            <input name="jq" type="text" id="jq" value="980"></td>
                          </tr>
                          <tr>
                            <td>车船税</td>
                            <td><label for="cc"></label>
                            <input name="cc" type="text" id="cc" value="420"></td>
                          </tr>
                          <tr>
                            <td>合计</td>
                            <td><span id="totalFeeAll">1400</span></td>
                          </tr>
                        </table>
                        </div>
                        </div>
                <table width="100%" border="0" cellspacing="1" cellpadding="0">
                          <tr>
                                <td colspan="4" bgcolor="#CCCCCC">客户类型</td>
                            </tr>
                            <tr>
                                <td colspan="4"><label>
                                    <label>
                                      <input type="radio" name="radio2" id="radio2" value="radio2">
                                金卡
                                <input type="radio" name="radio3" id="radio3" value="radio3">
                                白金卡
                              </label></label>
                              <input type="radio" name="radio" id="radio" value="radio">
钻石卡</td>
                            </tr>
                        </table>
                        <p>
                          <input name="submit" type="submit" value="保存" onClick="">
                        | <a href="/Ins/policy/del/${obj.PolicyObj.sn?default('')}" onClick="return confirm('确定删除?')">删除</a></p></p>

                        <p>
                    <label> </label>
                            <br>
                        </p>
                    </div>

                </form>
            </div>

        </div>
    </div>

[#include '../../bottom.ftl']
</div>
</body>
</html>